home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / gs24src.zip / ASTATE.H < prev    next >
C/C++ Source or Header  |  1992-03-03  |  4KB  |  105 lines

  1. /* Copyright (C) 1991 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* astate.h */
  21. /* State structures for the Ghostscript allocator */
  22.  
  23. /* Define pointers to an allocation state. */
  24. /****** Note the _ds (for Turbo C only). ******/
  25. typedef struct alloc_state_s alloc_state;
  26. typedef alloc_state _ds *alloc_state_ptr;
  27. /* The only instance.... */
  28. extern alloc_state_ptr alloc_state_current;
  29.  
  30. /* Round up sizes of aligned objects. */
  31. #define log2_align_mod 3        /* log2(sizeof(double)) */
  32. #define align_mod (1<<log2_align_mod)
  33. #define align_mask (align_mod-1)
  34. #define align_round(siz) (uint)(((siz) + align_mask) & -align_mod)
  35.  
  36. /* Max object size for separate free list */
  37. #define max_chain_size 350
  38.  
  39. /* Structure for a separately allocated block. */
  40. typedef struct alloc_block_s alloc_block;
  41. struct alloc_block_s {
  42.     alloc_block *next;
  43.     uint size;
  44.     int save_level;
  45.     alloc_state_ptr cap;
  46. };
  47. #define alloc_block_size align_round(sizeof(alloc_block))
  48.  
  49. /* Structure for a single wholesale allocation 'chunk'. */
  50. typedef struct alloc_chunk_s alloc_chunk;
  51. struct alloc_chunk_s {
  52.     /* Note that allocation takes place both from the bottom up */
  53.     /* (aligned objects) and from the top down (byte objects). */
  54.     byte *base;
  55.     byte *bot;            /* bottom of free area */
  56.                     /* (top of aligned objects) */
  57.     byte *top;            /* top of free area */
  58.                     /* (bottom of byte objects) */
  59.     byte *limit;
  60.     int save_level;            /* save level when this chunk */
  61.                     /* was allocated */
  62.     alloc_chunk *next;        /* chain chunks together */
  63. };
  64.  
  65. #define ptr_is_in_chunk(ptr, chunk)\
  66.   ptr_between(ptr, (chunk)->base, (chunk)->limit)
  67.  
  68. /* Structures for save/restore (not defined here). */
  69. struct alloc_save_s;
  70. struct alloc_change_s;
  71.  
  72. /* Structure for allocator state.  If we multi-thread some day, */
  73. /* this might be instantiated more than once. */
  74. struct alloc_state_s {
  75.     alloc_chunk current;        /* the current chunk */
  76. #define cbase current.base
  77. #define cbot current.bot
  78. #define ctop current.top
  79. #define climit current.limit
  80.     alloc_chunk *current_ptr;    /* where to put current */
  81.     uint chunk_size;        /* unit for wholesale malloc */
  82.     uint big_size;            /* min size for separate malloc */
  83.     proc_alloc_t palloc;        /* proc for malloc */
  84.     proc_free_t pfree;        /* proc for free */
  85.     /* Statistics */
  86.     long used;            /* total space used, including */
  87.                     /* malloc'ed blocks and all chunks */
  88.                     /* other than the current one */
  89.     long total;            /* total space allocated, */
  90.                     /* other than malloc'ed blocks */
  91.     unsigned num_chunks;
  92.     /* Chain together freed objects within a save level. */
  93.     /* We only do this for aligned objects. */
  94. #define num_free_chains ((max_chain_size >> log2_align_mod) + 1)
  95.     char *free[num_free_chains];
  96.     /* Chain together any malloc'ed objects */
  97.     alloc_block *malloc_chain;
  98.     /* Keep track of saved states */
  99.     int save_level;
  100.     struct alloc_save_s *saved;
  101.     byte *saved_cbot;        /* cbot at last save */
  102.     byte *saved_ctop;        /* ctop at last save */
  103.     struct alloc_change_s *changes;
  104. };
  105.